package com.firesrc.util;

import java.io.IOException;
import java.util.Date;

import jodd.datetime.JDateTime;

import org.h2.store.fs.FileUtils;
import org.h2.tools.CompressTool;
import org.h2.util.IOUtils;

public class SystemUtil {
	private static CompressTool instance = CompressTool.getInstance();;

	public static Date getCurrentDateYYYYMMDD() {
		JDateTime time = new JDateTime(System.currentTimeMillis());
		time.setFormat("YYYY-MM-DD");
		JDateTime time1 = new JDateTime(time.getYear(), time.getMonth(), time.getDay());
		Date convertToDate = time1.convertToDate();
		String jdtFormat = "YYYY-MM-DD";
		time.toString(jdtFormat);
		return convertToDate;
	}

	public static String getCurrentDateStringYYYYMMDD() {
		JDateTime time = new JDateTime(System.currentTimeMillis());
		time.setFormat("YYYY-MM-DD");
		String jdtFormat = "YYYY-MM-DD";
		return time.toString(jdtFormat);
	}

	public static String getCompressString(String text) {
		return new String(instance.compress(text.getBytes(), null));
	}

	public static String getExpandString(String compressString) {
		byte[] bytes = compressString.getBytes();
		byte[] expand = instance.expand(bytes);
		return new String(expand);
	}

	public static String getFileTextFromFileName(String filePath) {
		try {
			return IOUtils.readStringAndClose(IOUtils.getReader(FileUtils.newInputStream(filePath)), -1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
}
